package com.ktjy.web.interceptors;

import com.ktjy.entity.SysUser;
import jakarta.servlet.http.HttpServletRequest;
import jakarta.servlet.http.HttpServletResponse;
import jakarta.servlet.http.HttpSession;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.aop.framework.autoproxy.AbstractAutoProxyCreator;
import org.springframework.web.servlet.HandlerInterceptor;

/**
 * @author 黄军艳
 * @version 1.0
 * @date 2024/12/16  10:26
 */
public class AuthInterceptor implements HandlerInterceptor {
    private static final Logger LOGGER= LoggerFactory.getLogger(AbstractAutoProxyCreator.class);

    public boolean preHandle(final HttpServletRequest request, final HttpServletResponse response,Object handler) throws Exception {
        LOGGER.debug("进入自定义拦截器 AuthInterceptor，请求路径：{}",request.getRequestURI());
        HttpSession session=request.getSession();
        //获取登录用户
        SysUser sysUser=(SysUser)session.getAttribute("loginUser");
        if(sysUser==null){
            //没有登录信息
            request.getRequestDispatcher("/WEB-INF/jsp/401.jsp").forward(request, response);
            return false;
        }
        return true;
    }

}
